/*
 * @FileName: [LogAuditController.java]
 * 
 * @Package com.bcinfo.upp.admin.audit.controller
 * 
 * 
 * Copyright (c) 2011-2015 BCINFO Technology Limited Com. All rights reserved.
 * 
 * This software is the confidential and proprietary information of BCINFO Technology Limited Company ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only in accordance with the terms of the contract agreement you entered into with RKY.
 * 
 * $Rev: 43 $ $LastChangedDate: 2013-10-12 10:19:47 +0800 (星期六, 12 十月 2013) $ $LastChangedBy: wanggc $
 * 
 * @category bcinfo-upp
 * 
 * @version 1.1
 * 
 * @author $Author: wanggc $
 * 
 * Change History:[Formatter: author date description] <br/> 1 2 3
 */

package com.bcinfo.iccard.admin.audit.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.bcinfo.iccard.admin.common.ModuleEnum;
import com.bcinfo.iccard.admin.common.ModuleEnum.Audit;
import com.bcinfo.iccard.admin.controller.AbstractController;
import com.bcinfo.upp.audit.model.OpLog;
import com.bcinfo.upp.audit.service.OperationLogService;
import com.bcinfo.upp.exception.UppException;
import com.bcinfo.upp.util.PaginationList;

/**
 * 审计控制器 <br/>
 * <p>
 * Description:<br/>
 * <p>
 * 包含如下功能<br/>
 * 产看日志列表功能<br/>
 * 
 * <p>
 * For Examples <br/>
 * 
 * <PRE>
 *      http://127.0.0.1:8080/upp-admin/audit/log/toListView
 * </PRE>
 * <p>
 */
@Controller
@RequestMapping("/audit/log")
public class LogAuditController extends AbstractController
{
    @Autowired
    private OperationLogService _operationLogService;

    /**
     * 
     * 展示日志审计列表 <br/>
     * <p>
     * Description: 点击系统参数菜单时，展示日志审计列表 <br/>
     * <p>
     * Author: yangzq<br/>
     * <p>
     * Date: 2013-5-3-下午4:50:13<br/>
     * <p>
     * 
     * @return
     * 
     */
    @RequestMapping("toListView")
    public ModelAndView toListView()
    {
        return new ModelAndView("audit/log/log_list", "moduleName", ModuleEnum.UPP_MODULE_MAP);
    }

    /**
     * 
     * 获取日志审计列表(异步请求) <br/>
     * <p>
     * Description: 调用远程服务获取日志审计列表，返回日志审计列表 <br/>
     * <p>
     * Author: yangzq<br/>
     * <p>
     * Date: 2013-5-3-下午4:50:14<br/>
     * <p>
     * 
     * @return
     * 
     */
    @RequestMapping("/list")
    @ResponseBody
    public Map<String, Object> List(String beginTime, String endTime, Integer page, Integer rows, String moduleType,
            String content)
    {
        Map<String, Object> respMap = new HashMap<String, Object>(3);
        List<OpLog> paramterList = null;
        try
        {
            PaginationList<OpLog> pagList = _operationLogService.listByType(beginTime, endTime, rows, page, moduleType,
                    null, content);
            if (pagList != null)
            {
                respMap.put("total", pagList.getTotalRecord());
                List<OpLog> logListTemp = pagList.getRecords();
                if (logListTemp != null && !logListTemp.isEmpty())
                {
                    paramterList = logListTemp;
                }
            }
        }
        catch (UppException e)
        {
            handleException(e);
            respMap.put("total", 0);
        }
        catch (Exception e)
        {
            handleException(e);
            respMap.put("total", 0);
        }
        // 防止因list为空，造成easyui报错
        if (null == paramterList)
        {
            paramterList = new ArrayList<OpLog>();
        }
        respMap.put("rows", paramterList);

        return respMap;
    }

    /*
     * (non-Javadoc) Description: <br/>
     * 
     * @return
     * 
     * @see com.bcinfo.upp.admin.controller.AdminController#getMouduleCode()
     */
    @Override
    public String getMouduleCode()
    {
        return Audit.moduleName.value;
    }

}
